package com.rdc.qingkou.Application;

import android.app.Activity;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.rdc.qingkou.entity.User;
import com.rdc.qingkou.utils.UserUtil;

import net.arvin.socialhelper.SocialHelper;

import java.io.File;
import java.util.LinkedList;


public class MyApplication extends Application {

    private static Context sContext;
    private static File sCacheDir;
    private static ContentResolver sContentResolver;
    private static User sUser;
    private static String cookie;
    private static LinkedList<Activity> sActivityArrayList;
//    private List<Activity> activityList;
//    private static MyApplication instance;

    private static SocialHelper sSocialHelper;
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
        sContext = getApplicationContext();
        sCacheDir = getExternalCacheDir();
        sContentResolver = getContentResolver();
        sUser = null;
        cookie = "";
        sActivityArrayList = new LinkedList<>();

        sSocialHelper = new SocialHelper.Builder()
                .setQqAppId("1106533517")
                .setWxAppId("wxf420df38a2c15f45")
                .setWxAppSecret("83ade9c1269b6b472879a3fca2ac9f02")
                .setWbAppId("1919382822")
                .setWbRedirectUrl("http://sharesdk.cn")
                .build();

    }

    public static String getCookie() {
        return cookie;
    }

    public static void setCookie(String cookie) {
        MyApplication.cookie = cookie;
    }

    public static Context getContext(){
        return sContext;
    }
    public static File getAppCacheDir() {
        return sCacheDir;
    }
    public static  ContentResolver getsContentResolver(){
        return sContentResolver;
    }
    public static User getUser() {
        return sUser == null ? UserUtil.getCurrentUser() : sUser;
    }

    public static void setUser(User user) {
        UserUtil.saveUser(user);
        sUser = user;
    }

    public static void addActivity(Activity activity){
        sActivityArrayList.add(activity);
    }

    public static void delete()
    {
        for (Activity activity : sActivityArrayList)
        {
            activity.finish();
        }
        if (sActivityArrayList.size() == 0)
            sActivityArrayList.clear();
    }

//    public static MyApplication getInstance(){
//        if (null == instance){
//            instance = new MyApplication();
//        }
//        return instance;
//    }

    public static void exit(){
        for (Activity activity : sActivityArrayList) {
            activity.finish();
        }
        System.exit(0);
    }

    public static  SocialHelper getHelper(){
        
        return sSocialHelper;
    }

}
